package com.example.asus.zyfypt_tea_307plx.model;

import com.example.asus.zyfypt_tea_307plx.common.common;
import com.example.asus.zyfypt_tea_307plx.iface.RegisterListener;
import com.example.asus.zyfypt_tea_307plx.service.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by biangBiangbiu on 2018/6/9.
 */

public class RegisterModel {

    Retrofit retrofint;
    public RegisterModel(){
        retrofint = new Retrofit
                .Builder()
                .baseUrl(common.BASEURL)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
    }
    public void register(String userName, String passWord, String tel, final RegisterListener listener){
        RegisterService service = retrofint.create(RegisterService.class);
        Call<String> call=service.getReg(userName,passWord,tel);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if(response.body()!=null&&response.isSuccessful())
                {
                    listener.onResponse(response.body());
                }else
                {
                    listener.onFail("onresponse fail");
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail(t.toString());

            }
        });
    }



}
